package UIFree.controls
{
	import UIFree.uif_component;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class uif_vaScrollArea extends uif_scrollArea {
		private var _autoScroll: int;
		private var _step: Number;
		
		public function uif_vaScrollArea(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			_autoScroll = 0;
			_step		= 0;
			addEvent(MouseEvent.MOUSE_MOVE, doMove);
			addEvent(MouseEvent.ROLL_OUT, doOut);
			addEvent(Event.ENTER_FRAME, doFrame);
		}
		
		override public function attachList(list: Array, elemCreate:*): uif_scrollArea {
			super.attachList(list, elemCreate);
			_step = list?Math.round(area.height / list.length):0;
			return this;
		}
		
		protected function doFrame(e: Event): void {
			if ((_autoScroll != 0) && 
				(!area.getFX('y')))
				scrollTo(0, _autoScroll * _step);
		}

		protected function doOut(e: MouseEvent): void {
			_autoScroll = 0;
		}

		protected function doMove(e: MouseEvent): void {
			var mp: Point 		= mousePos;
			var harea: Number 	= height / 6;
			if (mp.y < harea) _autoScroll = 1;
			else if (mp.y > height - harea) _autoScroll = -1;
			else _autoScroll = 0;
		}
	}
}